package com.info.game;

import com.badlogic.gdx.math.Vector2;
import com.component.game.Component;
import com.component.game.InputComponent;
import com.engine.game.GameObject;
import com.engine.game.MessageInfo;

public class RedSquareInputComponent implements InputComponent{

	
//	private boolean needToUpdate = false;
	
	
	@Override
	public void dispose() {
		
		
	}

	@Override
	public void update(GameObject object) throws InstantiationException,
			IllegalAccessException, ClassNotFoundException {
		
		if(!FloodItConfiguration.isBlocked){
		
		for(MessageInfo message : object.getInputMessages()){
			
	//		if(this.needToUpdate){
				
	//			object.generate("spread;red", "SQUARE_1", Component.Render);
				
	//			this.needToUpdate = false;
	//		}
			
			
			if(message.message.contains("touch_down_on")){
				
				String[] parts = message.message.split(";");
				
				
				if(object.getRender().getSprite().getBoundingRectangle().contains(object.getWorldCoordinates(new Vector2(Integer.parseInt(parts[1]), Integer.parseInt(parts[2])))) &&
						(parts[3].equals("left"))){	
					
			//		this.needToUpdate = true;
					
					for(int i = 0; i < 196; i++){
						object.generate("set_unchecked", "SQUARE_" + Integer.toString(i+1), Component.Render);
					}
					
					object.generate("create;COUNTER", "CONFIGURATION", Component.Render);
					object.generate("spread;red", "SQUARE_1", Component.Render);
				}
				
			}
			
		}
		
	}
	}

}
